package java_class_work.socketDemo;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author Tiam
 * @Date 2022/11/9 17:00
 * @Description:
 */
public class Server {
    static Map<Integer, Socket> map = new HashMap<>();

    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(8888);
            while (true) {
                Socket accept = serverSocket.accept();
                // 将已连接的客户端端口存到list中, 及其对应的Socket存入
                map.put(accept.getPort(), accept);

                System.out.println(accept);
                new Thread(new ServerThread(accept)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
